package logic

import (
	"cart_srv/model/redis"
	"context"

	"cart_srv/cart"
	"cart_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartTotalLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartTotalLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartTotalLogic {
	return &CartTotalLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartTotalLogic) CartTotal(in *cart.CartTotalRequest) (*cart.CartTotalResponse, error) {
	// todo: add your logic here and delete this line
	count, amount := redis.CartTotal(int(in.UserId))

	return &cart.CartTotalResponse{
		Count:  int64(count),
		Amount: float32(amount),
	}, nil
}
